/*Version 1.0*/
#include "Barre_outils_animation.h"
#include "Boite_saisie_animation.h"
#include <string.h>


/*Creation de la barre d'outils*/
void CreationBarreOutilsAnimation(Scenario * sc,Marqueur * mq)
{
  Sc * S = malloc(sizeof(Sc));
  S->s = sc;
  S->m = mq;

  GtkWidget * pToolbar = NULL;
  /*Declaration des objets qui vont contenir les boutons*/
  GtkToolItem * D_GD = NULL;
  GtkToolItem * D_HB = NULL;
  GtkToolItem * S_X = NULL;
  GtkToolItem * R_Z = NULL;
  GtkToolItem * Jouer = NULL;
  GtkToolItem * Pause = NULL;
  GtkToolItem * Stop = NULL;
  
  /*Declaration de la fenetre et de la "boite" qui va contenir la barre d'outils*/
  GtkWidget *pWindow;
  GtkWidget *pVBox;

  /*Creation de la fenetre */
  pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(pWindow), "Barre Outils Animation");
  gtk_window_set_default_size(GTK_WINDOW(pWindow),720,20);

  pVBox = gtk_box_new(TRUE,0);
  gtk_container_add(GTK_CONTAINER(pWindow), pVBox);

  /* Creation de la barre d'outils */
  pToolbar = gtk_toolbar_new();
  gtk_box_pack_start(GTK_BOX(pVBox), pToolbar, FALSE, FALSE, 0);

  GtkWidget *button = gtk_button_new_with_label ("Deplacement_GD");
  GtkWidget *button2 = gtk_button_new_with_label ("Deplacement_HB");
  GtkWidget *button3 = gtk_button_new_with_label ("Scale_X");
  GtkWidget *button4 = gtk_button_new_with_label ("Rotation_Z");
  GtkWidget *button5 = gtk_button_new_with_label ("Jouer");
  GtkWidget *button6 = gtk_button_new_with_label ("Pause");
  GtkWidget *button7 = gtk_button_new_with_label ("Stop");

  gtk_widget_show (button);
  gtk_widget_show (button2);
  gtk_widget_show (button3);
  gtk_widget_show (button4);
  gtk_widget_show (button5);
  gtk_widget_show (button6);
  gtk_widget_show (button7);

  D_GD = gtk_tool_button_new(button,NULL);
  D_HB = gtk_tool_button_new(button2,NULL);
  S_X = gtk_tool_button_new(button3,NULL);
  R_Z = gtk_tool_button_new(button4,NULL);
  Jouer = gtk_tool_button_new(button5,NULL);
  Pause = gtk_tool_button_new(button6,NULL);
  Stop = gtk_tool_button_new(button7,NULL);

  /*Insertion des boutons dans la barre d'outils */
  gtk_toolbar_insert(GTK_TOOLBAR(pToolbar),D_GD,0);
  gtk_toolbar_insert(GTK_TOOLBAR(pToolbar),D_HB,-1);
  gtk_toolbar_insert(GTK_TOOLBAR(pToolbar),S_X,-1);
  gtk_toolbar_insert(GTK_TOOLBAR(pToolbar),R_Z,-1);
  gtk_toolbar_insert(GTK_TOOLBAR(pToolbar),Jouer,-1);
  gtk_toolbar_insert(GTK_TOOLBAR(pToolbar),Pause,-1);
  gtk_toolbar_insert(GTK_TOOLBAR(pToolbar),Stop,-1);


  gtk_widget_show_all(pWindow);

  /*Appels des fonctions de deplacement*/
  g_signal_connect (D_GD, "clicked",
                    G_CALLBACK (on_boutton_deplacementGD),(Sc*)S);
  g_signal_connect (D_HB, "clicked",
                    G_CALLBACK (on_boutton_deplacementHB),(Sc*)S);
  g_signal_connect (S_X, "clicked",
                    G_CALLBACK (on_boutton_changement_dechelleX),(Sc*)S);
  g_signal_connect (R_Z, "clicked",
                    G_CALLBACK (on_boutton_RotationZ),(Sc*)S);
  g_signal_connect (Jouer, "clicked",
                    G_CALLBACK (DeroulerScenario),(Sc*)S);
  
}

/*Fonctions qui appelent les fonctions d'animation quand les boutons de la barre d'outils sont actifs*/
gboolean on_boutton_deplacementGD(GtkButton *bouton, gpointer user_data)
{
  Sc * S=(Sc*)user_data;
  S->m->index_fonction=1;
  boite_saisie_animation(S->m,S->s);
  
  return TRUE;
}

gboolean on_boutton_deplacementHB(GtkButton *bouton, gpointer user_data)
{  
  Sc * S=(Sc*)user_data;
  S->m->index_fonction=2;
  boite_saisie_animation(S->m,S->s);

  return TRUE;
}

gboolean on_boutton_changement_dechelleX(GtkButton *bouton, gpointer user_data)
{ 
  Sc * S=(Sc*)user_data;
  S->m->index_fonction=3;
  boite_saisie_animation(S->m,S->s);

  return TRUE;
}

gboolean on_boutton_RotationZ(GtkButton *bouton, gpointer user_data)
{
  Sc * S=(Sc*)user_data;
  S->m->index_fonction=4;
  boite_saisie_animation(S->m,S->s);

  return TRUE;
}
